<template>
	<view class="exchangeList">
		<u-tabs :list="list1" itemStyle="padding-left: 32rpx; padding-right: 32rpx; height: 80rpx;background: #fff;"
			:activeStyle="{color: '#000000',fontWeight: 'bold'}" :lineColor="'#FC6758'" @click="click">
		</u-tabs>
		<view v-if="act==1" class="content_list">
			<view v-for="(item,index) in list" :key="index" class="item">
				<view class="left">
					<image src="../../static/tabsIcon/gold.png" mode=""></image>
					<view class="le_left">
						<view class="name">
							{{item.content}}
						</view>
						<view class="time">
							{{item.gmtCreate | times}}
						</view>
					</view>
				</view>
				<view class="right">
					{{item.isIncrease==1?'+':'-'}}{{item.pointsNum}}
				</view>
			</view>
		</view>
		<view v-if="act==2" class="content_list">
			<view v-for="(item,index) in list2" :key="index" class="item">
				<view class="left">
					<image src="../../static/tabsIcon/gold.png" mode=""></image>
					<view class="le_left">
						<view class="name">
							{{item.content}}
						</view>
						<view class="time">
							{{item.gmtCreate | times}}
						</view>
					</view>
				</view>
				<view class="right">
					{{item.isIncrease==1?'+':'-'}}{{item.bonusNum}}
				</view>
			</view>
		</view>
		<u-loadmore @loadmore="getmore()" :load-text="loadText" :status="status" />
	</view>
</template>

<script>
	import {
		exchangeslist,
		bonusrecordlist
	} from '@/api/mine'
	export default {
		data() {
			return {
				src: "../../static/tabsIcon/jifen.png",
				list: [],
				list2: [],
				act: 1,
				page: 1,
				size: 20,
				total: 0,
				status: 'loadmore',
				list1: [{
						name: '牛果记录',
						value: 1
					},
					{
						name: '牛角记录',
						value: 2
					}
				],
				loadText: {
					loadmore: '点击或上拉加载更多',
					loading: '努力加载中...',
					nomore: '没有更多了'
				},
			}
		},
		filters: {
			status(text) {
				let str = ""
				if (text == 0) {
					str = "申请中"
				}
				if (text == 1) {
					str = "成功"
				}
				if (text == 2) {
					str = "已驳回"
				}
				return str
			},
			times(value) {
				let date = new Date(value);
				let y = date.getFullYear(); // 年
				let MM = date.getMonth() + 1; // 月
				MM = MM < 10 ? ('0' + MM) : MM;
				let d = date.getDate(); // 日
				d = d < 10 ? ('0' + d) : d;
				let h = date.getHours(); // 时
				h = h < 10 ? ('0' + h) : h;
				let m = date.getMinutes(); // 分
				m = m < 10 ? ('0' + m) : m;
				let s = date.getSeconds(); // 秒
				s = s < 10 ? ('0' + s) : s;
				// var timer =  y + '-' + MM + '-' + d + ' ' + h + ':' + m + ':' + s;
				var timer = y + '-' + MM + '-' + d;
				return timer;
			}
		},
		onReachBottom() {
			if ((this.page * this.size) >= this.total) {
				this.status = 'nomore'
				return
			};
			// this.size = 20;
			this.status = 'loading';
			// this.page = this.page + 1;
			this.getmore()
		},
		onLoad() {
			this.getlist();
		},
		methods: {
			click(item) {
				this.act = item.value;
				this.page = 1;
				this.list = [];
				this.list2 = [];
				this.status = 'loading';
				if (this.act == 1) {
					this.getlist();
				} else {
					this.bonusrecordlist();
				}
			},
			getmore() {
				if ((this.page * this.size) >= this.total) {
					this.status = 'nomore'
					return
				};
				this.status = 'loading';
				this.page = this.page + 1;
				if (this.act == 1) {
					this.getlist();
				} else {
					this.bonusrecordlist();
				}
			},
			bonusrecordlist() {
				let data = {
					pageNum: this.page,
					pageSize: this.size
				}
				bonusrecordlist(data).then(res => {
					if (res.success == 1) {
						if (this.page == 1) {
							this.list2 = res.data.records;
						} else {
							this.list2.push(...res.data.records)
						}
						this.total = res.data.total;
						if ((this.page * this.size) >= this.total) {
							this.status = 'nomore'
						} else {
							this.status = 'loadmore'
						}
					} else {
						uni.showToast({
							icon: 'none',
							title: res.message
						})
					}
				})
			},
			getlist() {
				let data = {
					pageNum: this.page,
					pageSize: this.size
				}
				exchangeslist(data).then(res => {
					if (res.success == 1) {
						if (this.page == 1) {
							this.list = res.data.records;
						} else {
							this.list.push(...res.data.records)
						}
						this.total = res.data.total;
						if ((this.page * this.size) >= this.total) {
							this.status = 'nomore'
						} else {
							this.status = 'loadmore'
						}
					} else {
						uni.showToast({
							icon: 'none',
							title: res.message
						})
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	page {
		background: #e7e9ec;
	}

	.exchangeList {
		// width: 100%;
		padding: 20rpx;
	}

	.content_list {
		width: 100%;

		.item {
			background: #FFFFFF;
			border-radius: 12rpx;
			padding: 20rpx;
			display: flex;
			align-items: center;
			justify-content: space-between;
			margin: 20rpx 0;

			.left {
				width: 85%;
				display: flex;

				image {
					width: 90rpx;
					height: 90rpx;
					margin-right: 15rpx;
				}

				.le_left {
					width: 70%;
					height: 90rpx;
					display: flex;
					flex-direction: column;
					justify-content: space-between;

					.name {
						color: rgba(0, 0, 0, 0.9);
						font-size: 30rpx;
						font-weight: 600;
						// width: 70%;
					}

					.time {
						color: rgba(195, 195, 195, 0.9);
						font-size: 22rpx;
					}
				}
			}

			.right {
				color: #333333;
				font-size: 34rpx;
			}
		}
	}
</style>
